package com.yuexi.domain.table;

import com.yuexi.domain.repository.TableRepository;
import com.yuexi.domain.table.bo.TableBO;
import com.zenx.domain.Entity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author jie
 * @date 2023/4/5 -15:51
 */
@Entity
public class TableDomain {

    @Autowired
    private TableRepository repo;

    /**
     * 获取所有桌台
     */
    public List<TableBO> getAll() {
        return repo.getAll();
    }

    /**
     * 获取区域类型
     */
    public List<String> getAreaType(List<String> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return new ArrayList<>();
        }

        List<TableBO> tableBOList = repo.getByIds(ids);
        if (CollectionUtils.isEmpty(tableBOList)) {
            return new ArrayList<>();
        }

        return tableBOList.stream().map(TableBO::getAreaType).distinct().collect(Collectors.toList());
    }

    /**
     * 根据ids查询
     */
    public List<TableBO> getByIds(List<String> ids) {
        return repo.getByIds(ids);
    }
}
